<template>
  <div class="login-container">
    <!-- 左侧背景区域 -->
    <div class="login-banner">
      <div class="banner-content">
        <div class="logo">
          <img src="@/assets/images/logo.png" alt="医疗系统logo">
        </div>
        <h1>智慧医疗管理系统</h1>
        <p class="slogan">提供专业的医疗管理解决方案</p>
        <div class="feature-list">
          <div class="feature-item">
            <i class="icon-security"></i>
            <span>安全可靠的数据保护</span>
          </div>
          <div class="feature-item">
            <i class="icon-efficiency"></i>
            <span>高效的医疗资源管理</span>
          </div>
          <div class="feature-item">
            <i class="icon-innovation"></i>
            <span>创新的智能化服务</span>
          </div>
        </div>
      </div>
      <div class="banner-footer">
        <p>© 2024 智慧医疗管理系统 版权所有</p>
      </div>
    </div>

    <!-- 右侧登录区域 -->
    <div class="login-content">
      <div class="login-box">
        <!-- 标题 -->
        <div class="title">
          <h2>账号登录</h2>
          <p>欢迎回来，请输入您的账号信息</p>
        </div>

        <!-- 登录表单 -->
        <div class="login-form">
          <!-- 错误提示 -->
          <div class="error-message" v-if="errorMsg">
            <i class="icon-error"></i>
            {{ errorMsg }}
          </div>

          <!-- 用户名输入框 -->
          <div class="input-group">
            <label>用户名</label>
            <div class="input-wrapper">
              <div class="input-prefix">
                <i class="icon-user"></i>
              </div>
              <input type="text" v-model="loginForm.username" placeholder="请输入用户名" @keyup.enter="handleLogin">
              <div class="input-line"></div>
            </div>
          </div>

          <!-- 密码输入框 -->
          <div class="input-group">
            <label>密码</label>
            <div class="input-wrapper">
              <div class="input-prefix">
                <i class="icon-password"></i>
              </div>
              <input :type="showPassword ? 'text' : 'password'" v-model="loginForm.password" placeholder="请输入密码"
                @keyup.enter="handleLogin">
              <div class="input-suffix" @click="togglePasswordVisibility">
                <i :class="showPassword ? 'icon-eye-open' : 'icon-eye-close'"></i>
              </div>
              <div class="input-line"></div>
            </div>
          </div>

          <!-- 记住密码和忘记密码 -->
          <div class="remember-forgot">
            <label class="remember">
              <input type="checkbox" v-model="loginForm.remember">
              <span class="checkbox-custom"></span>
              <span>记住密码</span>
            </label>
            <span class="forgot" @click="handleForgotPassword">忘记密码？</span>
          </div>

          <!-- 登录按钮 -->
          <button class="login-button" :disabled="isLoading" @click="handleLogin">
            <div class="button-content">
              <span class="button-text">{{ isLoading ? '登录中' : '登 录' }}</span>
              <div class="button-loader" v-if="isLoading">
                <span></span>
                <span></span>
                <span></span>
              </div>
            </div>
          </button>

          <!-- 其他登录方式 -->
          <div class="other-login">
            <div class="divider">
              <span>其他登录方式</span>
            </div>
            <div class="login-icons">
              <i class="icon-wechat" title="微信登录"></i>
              <i class="icon-dingtalk" title="钉钉登录"></i>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, ref } from 'vue'
import { useRouter } from 'vue-router'

export default defineComponent({
  name: 'LoginView',
  setup() {
    const router = useRouter()
    const isLoading = ref(false)
    const showPassword = ref(false)
    const errorMsg = ref('')

    const loginForm = reactive({
      username: '',
      password: '',
      remember: false
    })

    // 表单验证
    const validateForm = () => {
      if (!loginForm.username.trim()) {
        errorMsg.value = '请输入用户名'
        return false
      }
      if (!loginForm.password) {
        errorMsg.value = '请输入密码'
        return false
      }
      if (loginForm.password.length < 6) {
        errorMsg.value = '密码长度不能小于6位'
        return false
      }
      errorMsg.value = ''
      return true
    }

    // 切换密码显示/隐藏
    const togglePasswordVisibility = () => {
      showPassword.value = !showPassword.value
    }

    // 处理登录
    const handleLogin = async () => {
      if (!validateForm()) return

      try {
        isLoading.value = true
        errorMsg.value = ''
        // 这里添加实际的登录逻辑
        await new Promise(resolve => setTimeout(resolve, 1000))
        router.push('/dashboard')
      } catch (error: any) {
        console.error('登录失败:', error)
        errorMsg.value = error.message || '登录失败，请重试'
      } finally {
        isLoading.value = false
      }
    }

    // 处理忘记密码
    const handleForgotPassword = () => {
      // 实现忘记密码逻辑
      alert('忘记密码功能开发中')
    }

    return {
      loginForm,
      isLoading,
      showPassword,
      errorMsg,
      togglePasswordVisibility,
      handleLogin,
      handleForgotPassword
    }
  }
})
</script>

<style scoped>
.login-container {
  min-height: 100vh;
  display: flex;
  background: #f5f7f9;
}

.login-banner {
  flex: 1;
  background: linear-gradient(135deg, #1a365d, #2193b0);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: white;
  padding: 60px 40px;
  position: relative;
  overflow: hidden;
}

.login-banner::before {
  content: '';
  position: absolute;
  width: 200%;
  height: 200%;
  background: url('data:image/svg+xml,<svg width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="40" stroke="rgba(255,255,255,0.1)" stroke-width="2" fill="none"/></svg>') repeat;
  animation: rotate 240s linear infinite;
  opacity: 0.2;
}

.banner-content {
  position: relative;
  z-index: 1;
  text-align: center;
}

.logo {
  margin-bottom: 40px;
}

.logo img {
  width: 120px;
  height: auto;
}

.banner-content h1 {
  font-size: 42px;
  font-weight: 600;
  margin-bottom: 20px;
  letter-spacing: 2px;
}

.slogan {
  font-size: 20px;
  opacity: 0.9;
  margin-bottom: 60px;
}

.feature-list {
  margin-top: 60px;
}

.feature-item {
  display: flex;
  align-items: center;
  margin-bottom: 30px;
  padding: 0 40px;
}

.feature-item i {
  font-size: 24px;
  margin-right: 15px;
}

.feature-item span {
  font-size: 16px;
  opacity: 0.9;
}

.banner-footer {
  text-align: center;
  opacity: 0.7;
  font-size: 14px;
}

.login-content {
  width: 600px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  padding: 40px;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.03);
}

.login-box {
  width: 100%;
  max-width: 460px;
}

.title {
  text-align: left;
  margin-bottom: 40px;
}

.title h2 {
  color: #1a365d;
  font-size: 32px;
  font-weight: 600;
  margin-bottom: 12px;
}

.title p {
  color: #666;
  font-size: 16px;
}

.input-group {
  margin-bottom: 25px;
}

.input-group label {
  display: block;
  margin-bottom: 8px;
  color: #1a365d;
  font-size: 14px;
  font-weight: 500;
}

.input-wrapper {
  position: relative;
  overflow: hidden;
}

.input-group input {
  width: 100%;
  padding: 12px 40px;
  border: 2px solid #eef0f6;
  border-radius: 8px;
  font-size: 16px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  background: #f8fafc;
}

.input-group input:focus {
  border-color: #2193b0;
  background: white;
  box-shadow: 0 0 0 3px rgba(33, 147, 176, 0.1);
  transform: translateY(-1px);
}

.input-line {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  width: 0;
  background: #2193b0;
  transition: width 0.3s ease;
}

.input-group input:focus+.input-line {
  width: 100%;
}

.input-prefix,
.input-suffix {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: #a0a9bd;
  transition: all 0.3s ease;
}

.input-prefix {
  left: 15px;
}

.input-suffix {
  right: 15px;
  cursor: pointer;
}

.remember-forgot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}

.remember {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #666;
  cursor: pointer;
}

.checkbox-custom {
  width: 18px;
  height: 18px;
  border: 2px solid #ddd;
  border-radius: 4px;
  position: relative;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.remember input[type="checkbox"] {
  display: none;
}

.remember input[type="checkbox"]:checked+.checkbox-custom {
  background: #2193b0;
  border-color: #2193b0;
}

.remember input[type="checkbox"]:checked+.checkbox-custom::after {
  content: '✓';
  color: white;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 12px;
  animation: checkmark 0.2s ease-in-out;
}

.forgot {
  color: #2193b0;
  cursor: pointer;
  transition: color 0.3s ease;
  font-size: 14px;
}

.forgot:hover {
  color: #1a7a8f;
  text-decoration: underline;
}

.login-button {
  width: 100%;
  padding: 14px;
  background: linear-gradient(to right, #1a365d, #2193b0);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.login-button:hover {
  background: linear-gradient(to right, #152c4e, #1c7a94);
  box-shadow: 0 5px 15px rgba(33, 147, 176, 0.3);
}

.login-button:disabled {
  background: linear-gradient(to right, #ccc, #ddd);
  cursor: not-allowed;
  box-shadow: none;
}

.button-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.button-loader {
  display: flex;
  gap: 4px;
}

.button-loader span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: white;
  animation: bounce 0.5s ease infinite;
}

.button-loader span:nth-child(2) {
  animation-delay: 0.1s;
}

.button-loader span:nth-child(3) {
  animation-delay: 0.2s;
}

@keyframes bounce {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-6px);
  }
}

.other-login {
  margin-top: 40px;
  text-align: center;
}

.divider {
  position: relative;
  margin: 20px 0;
}

.divider::before,
.divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: calc(50% - 100px);
  height: 1px;
  background: #eee;
}

.divider::before {
  left: 0;
}

.divider::after {
  right: 0;
}

.divider span {
  background: white;
  padding: 0 20px;
  color: #666;
  font-size: 14px;
}

.login-icons {
  display: flex;
  justify-content: center;
  gap: 30px;
  margin-top: 20px;
}

.login-icons i {
  font-size: 24px;
  color: #666;
  cursor: pointer;
  transition: all 0.3s ease;
}

.login-icons i:hover {
  color: #2193b0;
  transform: translateY(-2px);
}

.error-message {
  background: #fff2f0;
  border: 1px solid #ffccc7;
  padding: 8px 12px;
  border-radius: 4px;
  color: #ff4d4f;
  font-size: 14px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  animation: fadeIn 0.3s ease;
}

.error-message i {
  margin-right: 8px;
  font-size: 16px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1200px) {
  .login-banner {
    flex: 0.6;
  }

  .feature-list {
    margin-top: 40px;
  }
}

@media (max-width: 900px) {
  .login-banner {
    display: none;
  }

  .login-content {
    width: 100%;
    padding: 20px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
  }

  .login-box {
    padding: 20px;
    max-width: 400px;
  }
}
</style>